package descentFly.app.dialogs.levelsWindow
{
	import UIFree.ObjectEvent;
	import UIFree.uif_ecomponent;
	
	import descentFly.app.df_block;
	import descentFly.app.df_events;
	import descentFly.app.df_modalLayer;
	
	import flash.events.Event;
	
	public class df_onLineBattles extends df_battlesWindow {
		public static var DEFAULTBATTLE: Object = {
			battle_id	: 0,
			name		: ''
		}
		
		public function df_onLineBattles(a_parent:df_modalLayer, awidth:int, aheight:int, a_title:String, a_items:Object, a_itemClass:Class, a_event:String, canClose:int=1) {
			super(a_parent, awidth, aheight, a_title, a_items, a_itemClass, a_event, canClose);
		}
		
		override protected function createButtons(a_layer:df_block):void {
			super.createButtons(a_layer);
			addButton(locale.CREATEONLINEBATTLE, doCreateBattle);
		}
		
		override protected function doCreateItem(area: uif_ecomponent, item: Object, i: int): df_levelItem {
			item.description = Utils.sprintf(locale.ONLINEBATTLEINFO, [item.curUsers, item.maxUsers]);
			var result: df_levelItem = super.doCreateItem(area, item, i);
			result.disable = (item.maxUsers <= item.curUsers) || 
								(parseInt(Space.scene.battle_id) == parseInt(item.battle_id));
			return result;
		}
		
		protected function doCreateBattle(e: Event): void {
			ui.dispatchEvent(new ObjectEvent(df_events.SHOW_BATTLEPARAMS, DEFAULTBATTLE));
			close();
		}
	}
}